package com.shadow.baiqun.delegate.receive.adapter;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;

import com.shadow.baiqun.R;
import com.shadow.baiqun.config.ItemField;
import com.shadow.baiqun.config.ItemType;
import com.shadow.baiqun.delegate.receive.SupplierEntry;
import com.shadow.ui.recycler.MultipleItemEntity;
import com.shadow.ui.recycler.MultipleRecyclerAdapter;
import com.shadow.ui.recycler.MultipleViewHolder;

import java.util.List;

/**
 * @author zy
 * on 2018/5/20
 * 预收货
 */
public class SupplierListAdapter extends MultipleRecyclerAdapter {
    private static final int COUNT = 2;
    private int mColorWhite;
    private int mColorGray;
    public SupplierListAdapter(Context context, List<MultipleItemEntity> data) {
        super(data);
        mColorWhite = Color.WHITE;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            mColorGray = context.getColor(R.color.gray_light);
        }else{
            mColorGray = context.getResources().getColor(R.color.gray_light);
        }
        addItemType(ItemType.ITEM_SUPPLIER, R.layout.item_supplier);
    }

    @Override
    protected void convert(MultipleViewHolder helper, MultipleItemEntity item) {
        SupplierEntry supplierEntry = item.getField(ItemField.ITEM_OBJ);
        helper.setText(R.id.tv_supplier_name,supplierEntry.getSupplierName());
        helper.setText(R.id.tv_supplier_code, supplierEntry.getSupplierCode());
        helper.setText(R.id.tv_supplier_address,supplierEntry.getSupplierAddress());
        helper.setText(R.id.tv_supplier_dep, supplierEntry.getSupplierOrg());
        if(helper.getLayoutPosition() % COUNT == 1){
            helper.setBackgroundColor(R.id.layout_item,mColorWhite);
        }else{
            helper.setBackgroundColor(R.id.layout_item,mColorGray);
        }
    }
}
